package org.team4.service;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.team4.constants.SQLConstant;
import org.team4.dao.AttachedFileDAO;
import org.team4.dao.DAOFactory;
import org.team4.domain.AttachedFile;
import org.team4.exception.CRUDException;

import org.team4.service.IService;


@Service
public class AttachedFileService implements IService {

    private AttachedFileDAO attachedFileDAO;

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        attachedFileDAO = (AttachedFileDAO) DAOFactory.getDAO(sessionFactory, AttachedFileDAO.class);
    }

    /**
     * 根据对象ID查找附件
     * 
     * @param superId
     * @return
     * @throws CRUDException
     */
    public List<AttachedFile> findAttachedFileBySuperId(String superId) throws CRUDException {
        return attachedFileDAO.find(SQLConstant.ATTACHEDFILE_BY_SUPERID_HQL, superId);
    }

    /**
     * 删除附件
     * 
     * @param id
     * @throws CRUDException
     */
    public void delete(String id) throws CRUDException {
        attachedFileDAO.delete(id);
    }

    /**
     * 根据ID查找文件
     * 
     * @param id
     * @return
     * @throws CRUDException
     */
    public AttachedFile findFileById(String id) throws CRUDException {
        return attachedFileDAO.get(id);
    }
}
